﻿using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid.Views.Grid;
using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Const;
using RecruitStudents.Utility.Helper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Base
{
    public partial class Base_Teacher_List : BaseForm
    {
        ServiceBase service = new ServiceBase();
        public Base_Teacher_List()
        {
            InitializeComponent();
            cmbKGType.Properties.NullText = "";
            cmbSSZY.Properties.NullText = "";

            this.cmbSSZY.Properties.Columns.Add(new LookUpColumnInfo("SpecialityKindsID", "专业代码", 10));
            this.cmbSSZY.Properties.Columns.Add(new LookUpColumnInfo("SpecialityKindsName", "专业名称"));
            this.cmbSSZY.Properties.DataSource = service.GetSpecialityKindsTable("","","","");
            this.cmbSSZY.Properties.DisplayMember = "SpecialityKindsName";
            this.cmbSSZY.Properties.ValueMember = "SpecialityKindsNO";


            this.cmbKGType.Properties.Columns.Add(new LookUpColumnInfo("SpecialityKinds_DetailNO", "考官代码"));
            this.cmbKGType.Properties.Columns.Add(new LookUpColumnInfo("SpecialityKinds_DetailName", "考官类型"));
            this.cmbKGType.Properties.DataSource = service.GetSpecialityKindsDetailTable(string.Empty);
            this.cmbKGType.Properties.DisplayMember = "SpecialityKinds_DetailName";
            this.cmbKGType.Properties.ValueMember = "SpecialityKinds_DetailNO";


            BindData();
        }
        private void BindData()
        {
            string strcmbKGType = string.Empty;
            string strcmbSSZY = string.Empty;
            if (cmbKGType.Text == "" || cmbKGType.EditValue == null || cmbKGType.EditValue.ToSafeString().Length == 0)
            {
            }
            else
            {
                strcmbKGType = cmbKGType.EditValue.ToSafeString();
            }
            if (cmbSSZY.Text == "" || cmbSSZY.EditValue == null || cmbSSZY.EditValue.ToSafeString().Length == 0)
            {
            }
            else
            {
                strcmbSSZY = cmbSSZY.EditValue.ToSafeString();
            }
            using (DataTable dt = service.GetExaminerTable(txtLoginName.Text.ToSafeString(), txtName.Text.ToSafeString(), strcmbKGType.ToSafeString(), strcmbSSZY.ToSafeString(), ""))
            {
                dgExanim.DataSource = dt;
            }
        }

        private void benQuery_Click(object sender, EventArgs e)
        {
            BindData();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            Base_Teacher_Option option = new Base_Teacher_Option(string.Empty);
            if (option.ShowDialog() == DialogResult.OK)
            {
                this.BindData();
            }
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            GridView rows = sender as GridView;
            int[] inteurm = rows.GetSelectedRows();
            if (inteurm != null && inteurm.Length > 0)
            {
                string strExaminerID = rows.Rows[inteurm[0]].DataRow["ExaminerID"].ToSafeString();
                Base_Teacher_Option option = new Base_Teacher_Option(strExaminerID);
                if (option.ShowDialog() == DialogResult.OK)
                {
                    this.BindData();
                }
            }
        }
    }
}
